﻿using Microsoft.AspNetCore.Mvc;
using System.Data;
using Think9.Models;
using Think9.Services.Base;
using Think9.Services.Basic;

namespace Think9.Controllers.Basic
{
    public class MessageController : BaseController
    {
        private NotifyService NotifyService = new NotifyService();
        private ComService ComService = new ComService();

        /// <summary>
        /// 获取公告信息
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCount()
        {
            SmsEntity model = new SmsEntity();
            model.MsgCout = 100;
            return Json(model);
        }

        /// <summary>
        /// 获取公告信息
        /// </summary>
        /// <returns></returns>
        public JsonResult GetUnReadListJson()
        {
            DataTable dt = DataTableHelp.NewSmsDt();

            string sql = "select * from notify";
            foreach (DataRow dr in ComService.GetDataTable(sql).Rows)
            {
                DataRow row = dt.NewRow();
                row["SmsId"] = dr["NotifyId"].ToString();
                row["Type"] = 0;
                row["FromId"] = dr["FromId"].ToString();
                row["Subject"] = dr["Subject"].ToString();
                row["Content"] = dr["Content"].ToString();
                row["SendTime"] = dr["publishTime"].ToString();
                dt.Rows.Add(row);
            }

            sql = "select * from sms";
            foreach (DataRow dr in ComService.GetDataTable(sql).Rows)
            {
                DataRow row = dt.NewRow();
                row["SmsId"] = dr["SmsId"].ToString();
                row["Type"] = 99;
                row["FromId"] = dr["FromId"].ToString();
                row["Subject"] = "";
                row["Content"] = dr["Content"].ToString();
                row["SendTime"] = dr["SendTime"].ToString();
                dt.Rows.Add(row);
            }

            return Json(DataTableHelp.ToEnumerable<SmsEntity>(dt));
        }
    }
}